#!/usr/bin/env perl

BEGIN {
	push @::INC,".." if -f "../pv3.pm";
	push @::INC,$::ENV{CODEMGR_LIBS} if exists($::ENV{CODEMGR_LIBS});
}

use pv3;
use Getopt::Long;
use Config;
use strict;

sub usage {
	print "
Usage: pv3_sha1sum file ...

Returns the SHA1 checksums of all files specified.

Written by Simon Edwards, (C) 2006-2010 www.advantsys.co.uk
";
	exit 1;
}

if(!GetOptions(
	)) {
	usage;
}

if($Config{osname} =~ /mswin/i) {
	my @F=();
	for my $cpat (@ARGV) {
		push @F,glob($cpat);
	}
	@ARGV=@F;
}

for my $cfile (@ARGV) {
	next if -d $cfile;
	next if $cfile =~ /,pv3$/;
	if(! -f $cfile) {
		print "ERROR: File '$cfile' does not exist - ignoring.\n";
		next;
	}
	my $ck=pv3::_sha1sum($cfile);
	if(defined($ck)) {
		printf("%-40s $cfile\n",$ck);

	} else {
		printf("%-40s $cfile\n","UNREADABLE");
	}
}

exit(0);
